package com.lap.auth.domain.api;

import com.lap.auth.domain.api.valueobject.*;
import com.lap.framework.tools.EnumUtil;

/**
 * API基础转换字段
 *
 * @author Shuisheng Lao(劳水生)
 * @version 0.0.1
 */
public interface BaseApiConverter {

  // ===== HttpMethod =====
  default HttpMethod codeToHttpMethod(String code) {
    return EnumUtil.fromCode(HttpMethod.class, code);
  }

  default String httpMethodToCode(HttpMethod method) {
    if (method == null) return null;
    return method.getCode();
  }

  // ===== ApiType =====
  default ApiType codeToApiType(Integer code) {
    return EnumUtil.fromCode(ApiType.class, code);
  }

  default Integer apiTypeToCode(ApiType type) {
    return type.getCode();
  }

  // ===== AccessLevel =====
  default AccessLevel codeToAccessLevel(Integer code) {
    return EnumUtil.fromCode(AccessLevel.class, code);
  }

  default Integer accessLevelToCode(AccessLevel accessLevel) {
    return accessLevel.getCode();
  }

  // ===== ViewType =====
  default ViewType codeToViewType(Integer code) {
    return EnumUtil.fromCode(ViewType.class, code);
  }

  default Integer viewTypeToCode(ViewType type) {
    return type.getCode();
  }

  // ===== UpdatedFlag =====
  default UpdatedFlag codeToUpdatedFlag(Integer code) {
    return EnumUtil.fromCode(UpdatedFlag.class, code);
  }

  default Integer updatedFlagToCode(UpdatedFlag flag) {
    return flag.getCode();
  }
}
